package com.ict.web.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ict.common.annotation.Excel;
import com.ict.common.utils.DateUtils;
import com.ict.common.utils.bean.BeanUtils;
import com.ict.common.utils.uuid.IdUtils;
import com.ict.web.controller.file.domain.YzqFile;
import com.ict.web.controller.file.dto.YzqFileDTO;
import com.ict.web.domain.ExpertInformationSheet;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
public class UpdateExpertInformationSheetDto {

  @ApiModelProperty(value = "专家id")
  @JsonFormat(shape = JsonFormat.Shape.STRING)
  @TableId(type = IdType.ASSIGN_ID)
  private Long expertId;

  /**
   * 专家姓名
   */
  @Excel(name = "专家姓名")
  private String expertName;

  /**
   * 性别（0：男，1：女）
   */
  @Excel(name = "性别", readConverterExp = "0=：男，1：女")
  private String sex;

  /**
   * 政治面貌
   */
  @Excel(name = "政治面貌")
  private String politicalOutlook;

  /**
   * 身份证号码
   */
  @Excel(name = "身份证号码")
  private String idNumber;

  /**
   * 手机号码
   */
  @Excel(name = "手机号码")
  private String phoneNumber;

  /**
   * 电子邮箱
   */
  @Excel(name = "电子邮箱")
  private String email;

  /**
   * 联系地址
   */
  @Excel(name = "联系地址")
  private String contactAddress;

  /**
   * 毕业学院
   */
  @Excel(name = "毕业学院")
  private String graduateCollege;

  /**
   * 专业
   */
  @Excel(name = "专业")
  private String major;

  /**
   * 学历
   */
  @Excel(name = "学历")
  private String education;

  /**
   * 毕业时间
   */
  @ApiModelProperty(value = "毕业时间")
  @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8",shape = JsonFormat.Shape.STRING)
  @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
  private Date graduationTime;

  /**
   * 工作单位
   */
  @Excel(name = "工作单位")
  private String workUnit;

  /**
   * 职务
   */
  @Excel(name = "职务")
  private String post;

  /**
   * 擅长领域
   */
  @Excel(name = "擅长领域")
  private String areasOfExpertise;

  /**
   * 工作年限
   */
  @Excel(name = "工作年限")
  private String workingYears;


  /**
   * 最高学历证书
   */
  @Excel(name = "最高学历证书")
  private YzqFileDTO haCertificateFile;

  /**
   * 工作单位意见
   */
  @Excel(name = "工作单位意见")
  private YzqFileDTO workUnitOpinionsFile;

  /**
   * 身份证
   */
  @Excel(name = "身份证")
  private YzqFileDTO idCardFile;

  /**
   * 个人照片
   */
  @Excel(name = "个人照片")
  private YzqFileDTO personalPhotosFile;

  @Excel(name = "年龄")
  private Integer age;

  @ApiModelProperty(value = "职业资格表")
  private List<InsertProfessionalQualificationDto> qualificationAddDtoS;

  @ApiModelProperty(value = "技术职称")
  private List<InsertTechnicalTitleDto> technicalTitleDtoS;

  public static ExpertInformationSheet of(UpdateExpertInformationSheetDto updateDto){
    ExpertInformationSheet bean = new ExpertInformationSheet();
    BeanUtils.copyProperties(updateDto,bean);
    bean.setUpdateTime(DateUtils.getNowDate());

    return bean;
  }

  /**
   * 将 UpdateExpertInformationSheetDto中需传文件对象 转化为 file
   *
   * @param dto 接收dto
   * @return HotelInfo
   */
  public static ArrayList<YzqFile> toFile(ExpertInformationSheet expertInformationSheet, UpdateExpertInformationSheetDto dto) {
    ArrayList<YzqFile> fileList = new ArrayList<>();
    if (dto.getHaCertificateFile() != null) {
      YzqFileDTO Hc = dto.getHaCertificateFile();
      YzqFile fileHc = new YzqFile();
      fileHc.setId(String.valueOf(IdUtils.snowId()));
      BeanUtils.copyProperties(Hc, fileHc);
      fileList.add(fileHc);
      expertInformationSheet.setHaCertificateFile(fileHc.getId());
    }

    if (dto.getWorkUnitOpinionsFile() != null) {
      YzqFileDTO Wo = dto.getWorkUnitOpinionsFile();
      YzqFile fileWo = new YzqFile();
      fileWo.setId(String.valueOf(IdUtils.snowId()));
      BeanUtils.copyProperties(Wo, fileWo);
      fileList.add(fileWo);
      expertInformationSheet.setWorkUnitOpinionsFile(fileWo.getId());
    }

    if (dto.getIdCardFile() != null) {
      YzqFileDTO Ic = dto.getIdCardFile();
      YzqFile fileIc = new YzqFile();
      fileIc.setId(String.valueOf(IdUtils.snowId()));
      BeanUtils.copyProperties(Ic, fileIc);
      fileList.add(fileIc);
      expertInformationSheet.setIdCardFile(fileIc.getId());
    }

    if (dto.getPersonalPhotosFile() != null) {
      YzqFileDTO Pp = dto.getPersonalPhotosFile();
      YzqFile filePp = new YzqFile();
      filePp.setId(String.valueOf(IdUtils.snowId()));
      BeanUtils.copyProperties(Pp, filePp);
      fileList.add(filePp);
      expertInformationSheet.setPersonalPhotosFile(filePp.getId());
    }

    return fileList;
  }
}
